package com.ruif.util;

import java.sql.Connection;
import java.sql.DriverManager;

public class DBUtil
{
    private String dbUrl = "jdbc:mysql://localhost:3306/ruif";
    private String dbUserName = "root";
    private String dbPassword = "123456";
    private String jdbcName = "com.mysql.jdbc.Driver";
    
    /**
     * 获取数据库连接
     * @return
     * @throws Exception
     */
    public Connection getConn() throws Exception
    {
        Class.forName(jdbcName);
        Connection conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword);
        return conn;
    }
    
    /**
     * 关闭数据库连接
     * @param conn
     * @throws Exception
     */
    public void closeConn(Connection conn) throws Exception
    {
        if (conn != null)
        {
            conn.close();
        }
    }
    
}
